package com.rui.study.algorithm.learn_栈数组栈;

/**
 * @program: study_20180903
 * @description:
 * @author: Yaowr
 * @create: 2018-10-24 08:56
 **/
public class Test {

    private static void case1() {
        Stack<Integer> stack = new Stack<Integer>();
        for (int i = 0; i < 100; i++) {
            stack.push(i);
        }

        assert stack.size() == 100;

        boolean p1 = stack.push(10);
        assert p1 == true;

        Integer po1 = stack.pop();
        assert po1 == 10;

        assert stack.size() == 100;

        for (int i = 0; i < 100; i++) {
            Integer poi = stack.pop();
            assert poi != null;
        }

        Integer po2 = stack.pop();
        assert po2 == null;
    }

    private static void case2() {
        Stack<Character> stack = new Stack<Character>();
        String s1 = "abc{s{{s}n{sd{}}{{{}}}}";
        for (int i = 0; i < s1.length(); i++) {

            char c = s1.charAt(i);
            if (c == 123) { // '{'
                boolean pui = stack.push(c);
                assert pui == true;
            }

            if (c == 125) { // '}'
                char pc = stack.pop();
                assert pc == 123;
            }
        }

        int size = stack.size();
        assert size == 1;
    }

    public static void main(String[] args) {
        case1();
        case2();
    }
}
